package ru.gdnet 
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author Wernher
	 */
	public class TBoard extends Sprite 
	{
		public const MATCH_COUNT:int = 33;
		public var macthCount:int = MATCH_COUNT;
		
		private var fboard:Vector.<TMatch> = new Vector.<TMatch>();
		private var btn1:btn_1 = new btn_1();
		private var btn2:Tbtn_2 = new Tbtn_2();
		private var btn3:Tbtn_3 = new Tbtn_3();
		private var btn_newGame:Tbtn_NG = new Tbtn_NG();
		
		public function TBoard() 
		{
			super();
			//рисуем спички
			var i:int = 0;
			while (i < MATCH_COUNT) {
				this.fboard[i] = new TMatch();
				this.fboard[i].x = (i * 20)+30;
				this.fboard[i].y = 100;
				addChild(this.fboard[i]);
				this.fboard[i].gotoAndPlay(1);
				i++;
			}
			
			//рисуем кнопку 1
			btn1.x = 50;
			btn1.y = 250;
			addChild(btn1);
			btn1.addEventListener(MouseEvent.CLICK, this.getMatch_1);
			//рисуем кнопку 2
			btn2.x = 120;
			btn2.y = 250;
			addChild(btn2);
			btn2.addEventListener(MouseEvent.CLICK, this.onBtn2Click);
			//рисуем кнопку 3
			btn3.x = 190;
			btn3.y = 250;
			addChild(btn3);
			btn3.addEventListener(MouseEvent.CLICK, this.onBtn3Click);
			//рисуем кнопку New
			btn_newGame.x = 320;
			btn_newGame.y = 250;
			addChild(btn_newGame);
			btn_newGame.addEventListener(MouseEvent.CLICK, this.onNewGameClick);
			
			this.macthCount = this.fboard.length;
			trace(this.macthCount);
		}
		//Убераем 1 спичку
		public function getMatch_1(e:MouseEvent):void {
			if (this.macthCount > 0){
				this.fboard[this.macthCount - 1].visible = false;
				this.macthCount--;
			}
		}
		
		public function onBtn2Click(e:MouseEvent):void {
			this.getMatch_1(e);
			this.getMatch_1(e);
		}
		
		public function onBtn3Click(e:MouseEvent):void {
			this.getMatch_1(e);
			this.getMatch_1(e);
			this.getMatch_1(e);
		}
		//Начинаем новую игру
		public function onNewGameClick(e:MouseEvent):void {
			var i:int = 0;
			while (i < this.MATCH_COUNT) {
				this.fboard[i].visible = true;
				i++;
			}
			this.macthCount = this.fboard.length;
			trace(this.macthCount);
		}
	}

}